<?php

/**
 * This is the model class for table "quotation_request".
 *
 * The followings are the available columns in table 'quotation_request':
 * @property string $id
 * @property string $quotation_request_number
 * @property string $trans_date
 * @property string $note
 * @property integer $id_user_request
 * @property integer $id_user_acknowledge
 * @property integer $status
 * @property string $supplier_code
 * @property string $supplier_name
 * @property string $currency
 * @property string $id_inquiry
 * @property string $supplier_id
 * @property string $lead_time
 * @property string $payment_term
 * @property integer $status_list_create_po
 *
 * The followings are the available model relations:
 * @property QuotationRequestDetail[] $quotationRequestDetails
 */
class QuotationRequest extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return QuotationRequest the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'quotation_request';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('quotation_request_number', 'required'),
			array('id_user_request, id_user_acknowledge, status, status_list_create_po', 'numerical', 'integerOnly'=>true),
			array('quotation_request_number, supplier_code', 'length', 'max'=>255),
			array('supplier_name, currency, payment_term', 'length', 'max'=>50),
			array('id_inquiry, supplier_id, lead_time', 'length', 'max'=>19),
			array('trans_date, note', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, quotation_request_number, trans_date, note, id_user_request, id_user_acknowledge, status, supplier_code, supplier_name, currency, id_inquiry, supplier_id, lead_time, payment_term, status_list_create_po', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'quotationRequestDetails' => array(self::HAS_MANY, 'QuotationRequestDetail', 'id_quotation_request'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'quotation_request_number' => 'Quotation Request Number',
			'trans_date' => 'Trans Date',
			'note' => 'Note',
			'id_user_request' => 'Id User Request',
			'id_user_acknowledge' => 'Id User Acknowledge',
			'status' => 'Status',
			'supplier_code' => 'Supplier Code',
			'supplier_name' => 'Supplier Name',
			'currency' => 'Currency',
			'id_inquiry' => 'Id Inquiry',
			'supplier_id' => 'Supplier',
			'lead_time' => 'Lead Time',
			'payment_term' => 'Payment Term',
			'status_list_create_po' => 'Status List Create Po',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('quotation_request_number',$this->quotation_request_number,true);
		$criteria->compare('trans_date',$this->trans_date,true);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('id_user_request',$this->id_user_request);
		$criteria->compare('id_user_acknowledge',$this->id_user_acknowledge);
		$criteria->compare('status',$this->status);
		$criteria->compare('supplier_code',$this->supplier_code,true);
		$criteria->compare('supplier_name',$this->supplier_name,true);
		$criteria->compare('currency',$this->currency,true);
		$criteria->compare('id_inquiry',$this->id_inquiry,true);
		$criteria->compare('supplier_id',$this->supplier_id,true);
		$criteria->compare('lead_time',$this->lead_time,true);
		$criteria->compare('payment_term',$this->payment_term,true);
		$criteria->compare('status_list_create_po',$this->status_list_create_po);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function search2($id)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->condition = "supplier_id=".$id;
		$criteria->compare('id',$this->id,true);
		$criteria->compare('quotation_request_number',$this->quotation_request_number,true);
		$criteria->compare('trans_date',$this->trans_date,true);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('id_user_request',$this->id_user_request);
		$criteria->compare('id_user_acknowledge',$this->id_user_acknowledge);
		$criteria->compare('status',$this->status);
		$criteria->compare('supplier_code',$this->supplier_code,true);
		$criteria->compare('supplier_name',$this->supplier_name,true);
		$criteria->compare('currency',$this->currency,true);
		$criteria->compare('id_inquiry',$this->id_inquiry,true);
		$criteria->compare('supplier_id',$this->supplier_id,true);
		$criteria->compare('lead_time',$this->lead_time,true);
		$criteria->compare('payment_term',$this->payment_term,true);
		$criteria->compare('status_list_create_po',$this->status_list_create_po);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}